package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.dubbo.api.BlackListApi;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service(timeout = 200000)
public class BlackListApiImpl implements BlackListApi {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public IPage<UserInfo> findBlacklist(Long userId, Integer page, Integer pagesize) {
        // 创建分页对象：封装分页参数
        IPage param = new Page(page,pagesize);
        // 调用mapper分页查询
        return userInfoMapper.findBlacklist(param,userId);
    }

    @Override
    public void deleteBlackUser(Long userId, Long blackUserId) {
        // 根据条件删除:DELETE FROM tb_black_list WHERE user_id=1 AND black_user_id=50
        // 构造条件对象
        QueryWrapper<BlackList> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId).eq("black_user_id",blackUserId);
        blackListMapper.delete(wrapper);
    }
}
